import 'package:flutter/material.dart';
import 'package:flutter_study/changenotifier/test_consumer_notifier.dart';
import 'package:flutter_study/changenotifier/test_selector_notifier.dart';
import 'package:flutter_study/models/TestOne.dart';
import 'package:flutter_study/routers/study_router.dart';
import 'package:provider/provider.dart';

import 'routers/fluro_navigator.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp() {
    NavigatorUtils.initRouter();
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => TestConsumerNotifier()),
        ChangeNotifierProvider(create: (_) => TestSelectorNotifier(TestOne("张三","28")))
      ],
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Flutter Widget Study'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, this.title}) : super(key: key);

  final String? title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List<String> widgets = [
    "SafeArea",
    "Expanded",
    "AnimatedContainer",
    "provider",
    "AnimatedBuilder",
    "AnimatedBuilder2",
    "AnimatedBuilder3",
    "CustomPaint",
    "CustomMultiChild",
    "RenderBox",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title ?? ""),
        ),
        body: ListView.builder(
          itemCount: widgets.length,
          itemBuilder: (context, index) {
            return itemWidget(index);
          },
        ));
  }

  Widget itemWidget(int index) {
    return InkWell(
      onTap: () {
        NavigatorUtils.push(context, StudyRouter.getNameByPos(index));
      },
      child: Container(
        height: 40,
        alignment: Alignment.center,
        child: Text(widgets[index],style: TextStyle(color: Colors.white),),
        color: Colors.blue,
      ),
    );
  }
}
